package base;

public class Basic {
    //Java Structure

    //常量
    static final double PI = 3.14;

    //类变量
    static double salary = 2500;

    //实例变量
    public String autor;

    public void toDo() {
        //局部变量
        String thing;
        System.out.println(PI);

    }

    public static void expandInteger() {
        //进制    二进制0b 十进制 八进制0 十六进制0x
        int i1 = 10;
        int i2 = 010;
        int i3 = 0x10;
        System.out.println(i1+","+i2+","+i3);
    }

    public static void expandFloat() {
        //float?double
        float f = 0.1f;
        double d = 1.0/10;

        float f1 = 135797531.135797531f;
        float f2 = 135797531.135797531f+1;

        //最好完全避免浮点数进行比较
        //BigDecimal 数学工具类
        System.out.println(f==d);
        System.out.println(f1==f2);
    }

    public static void expandChar() {
        char ch1 = 'a';
        char ch2 = '中';
        System.out.println(ch1+"="+(int)ch1);
        System.out.println(ch2+"="+(int)ch2);
        //所有的字符本质还是数字
        //编码    Unicode 0~65536    范围U0000~UFFFF
        char ch3 = '\u0062';
        //转义字符\
        System.out.println(ch3+"\t转义字符\n");

        //内存分析
        String sa = "hello!";
        String sb = "hello!";
        System.out.println(sa==sb);
        String sc = "hello!";
        String sd = "hello!";
        System.out.println(sc==sd);
    }

    public static void expandBoolean() {
        boolean flag = true;
        if (flag==true) {
            //more is wrong
        }
        if (flag) {
            //less is more
        }
    }

    public static void main(String[] args) {
        /*
        注意程序的可读性
         */
        //整数类型
        byte num1 = 123;
        short num2 = 1234;
        int num3 = 12345;
        long num4 = 123456L;
        //浮点类型
        float num5 = 11.22F;
        double num6 = 22.33;
        //字符类型
        char info = 'l';
        //布尔类型
        boolean flag = true;

        //String是类，而不是关键字
        String name = "CphRed";

        expandInteger();
        expandFloat();
        expandChar();
        //关键字也存在包装类，例如int,char,boolean
        System.out.println(name);
        System.out.println("Hello world!");

        //类型转换
        char ch = 'a';
        int num = ch+1;
        System.out.println(num);
        System.out.println((char) num);
        //大数操作是，注意溢出问题
        //JDK7新特性，数字之间可以用下划线(_)分割
        int money = 10_0000_0000;
        int multiple = 20;
        int total = money*multiple;
        System.out.println(total);
        long result = total;
        System.out.println(result);
        System.out.println((long)money*multiple);
    }
    /*
        There are more blocks
        This is funny
     */
}
